package backtracking;

import NodeList.ListNode;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * @ Author     ：侯耀祖
 * @ Description：
 */
public class permute {
    List<List<Integer>> result = new ArrayList<>();
    LinkedList<Integer> path = new LinkedList<>();
    boolean[] used;
    public List<List<Integer>> permute(int[] nums) {
        used = new boolean[nums.length];
        backtracking(nums);
        return result;
    }
    public void backtracking(int[] nums){
        if (path.size() == nums.length){
            result.add(new ArrayList<>(path));
        }
        for (int i = 0, numsLength = nums.length; i < numsLength; i++) {
            int num = nums[i];
            if (used[i]) {
                continue;
            }
            used[i] = true;
            path.add(num);
            backtracking(nums);
            path.removeLast();
            used[i] = false;
        }
    }
}
